package com.scalar.forecast.projectSetup.actionCommands;

import com.scalar.forecast.actionCommands.ActionCommand;
import com.scalar.forecast.projectSetup.dao.UserDefinedFieldsDAO;
import com.scalar.forecast.commons.SessionKeys;

import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;

/**
 * Processes request to load user defined field( of type list) values
 *
 * Created by Veeru. 
 * Date: Feb 14, 2005
 * Time: 1:57:20 PM 
 */


public class UserDefinedListValuesModifyCommand extends ActionCommand {

    public ActionForward execute( ActionMapping mapping,
                                  ActionForm form,
                                  HttpServletRequest request,
                                  HttpServletResponse response ) {

        ActionForward actionForward = mapping.findForward( "userDefinedLisValues" );

        int projectId = 0;
        String list   = null;
        HashMap errors = new HashMap ();
        request.setAttribute( SessionKeys.ERROR_MESSAGES, errors );

        if ( request.getParameter( "projectId" ) != null && request.getParameter( "listName" ) != null ) {
            try {
                projectId = Integer.parseInt( request.getParameter("projectId").trim() );
                list      = request.getParameter( "listName" ).trim();
                ArrayList userDefinedListValues = UserDefinedFieldsDAO.loadUserDefinedListValues( null, projectId, "PROJSETUP", list );
                request.setAttribute("list", userDefinedListValues);

            } catch ( Exception e ) {
                errors.put( "Error: Could not load User Defined List Values", null );
            }
        }
        return actionForward;
    }
}
